package com.novunda.platform.common.dialects.shiro;

import com.novunda.platform.common.dialects.shiro.processor.AuthenticatedAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.AuthenticatedElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.GuestAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.GuestElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAllPermissionsAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAllPermissionsElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAllRolesAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAllRolesElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAnyPermissionsAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAnyPermissionsElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAnyRolesAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasAnyRolesElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasPermissionAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.HasPermissionElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.LacksPermissionAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.LacksPermissionElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.LacksRoleAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.LacksRoleElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.NotAuthenticatedAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.NotAuthenticatedElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.PrincipalAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.PrincipalElementProcessor;
import com.novunda.platform.common.dialects.shiro.processor.UserAttributeProcessor;
import com.novunda.platform.common.dialects.shiro.processor.UserElementProcessor;
import org.thymeleaf.dialect.AbstractProcessorDialect;
import org.thymeleaf.processor.IProcessor;
import org.thymeleaf.standard.StandardDialect;

import java.util.HashSet;
import java.util.Set;

/**
 * @author linfeng
 * @since 2016/9/9
 */
public class ShiroDialect extends AbstractProcessorDialect {

    private static final String DIALECT_NAME = "Shiro Dialect";
    private static final int DIALECT_PRECEDENCE = 1200;

    public ShiroDialect() {
        super(DIALECT_NAME, "shiro", StandardDialect.PROCESSOR_PRECEDENCE);
    }

    @Override
    public Set<IProcessor> getProcessors(final String dialectPrefix) {

        final Set<IProcessor> processors = new HashSet<IProcessor>();

        processors.add(new AuthenticatedAttributeProcessor(dialectPrefix));
        processors.add(new AuthenticatedElementProcessor(dialectPrefix));

        processors.add(new GuestAttributeProcessor(dialectPrefix));
        processors.add(new GuestElementProcessor(dialectPrefix));

        processors.add(new HasAllPermissionsAttributeProcessor(dialectPrefix));
        processors.add(new HasAllPermissionsElementProcessor(dialectPrefix));

        processors.add(new HasAllRolesAttributeProcessor(dialectPrefix));
        processors.add(new HasAllRolesElementProcessor(dialectPrefix));

        processors.add(new HasAnyPermissionsAttributeProcessor(dialectPrefix));
        processors.add(new HasAnyPermissionsElementProcessor(dialectPrefix));

        processors.add(new HasAnyRolesAttributeProcessor(dialectPrefix));
        processors.add(new HasAnyRolesElementProcessor(dialectPrefix));

        processors.add(new HasPermissionAttributeProcessor(dialectPrefix));
        processors.add(new HasPermissionElementProcessor(dialectPrefix));

        processors.add(new LacksPermissionAttributeProcessor(dialectPrefix));
        processors.add(new LacksPermissionElementProcessor(dialectPrefix));

        processors.add(new LacksRoleAttributeProcessor(dialectPrefix));
        processors.add(new LacksRoleElementProcessor(dialectPrefix));

        processors.add(new NotAuthenticatedAttributeProcessor(dialectPrefix));
        processors.add(new NotAuthenticatedElementProcessor(dialectPrefix));

        processors.add(new PrincipalAttributeProcessor(dialectPrefix));
        processors.add(new PrincipalElementProcessor(dialectPrefix));

        processors.add(new UserAttributeProcessor(dialectPrefix));
        processors.add(new UserElementProcessor(dialectPrefix));


        return processors;

    }


}
